using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace Colorprj
{
    public partial class frmrptSOA : Form
    {
        public frmrptSOA()
        {
            InitializeComponent();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            showReport(dtpDateFrom.Value, dtpdateto.Value);
        }


        private void showReport(DateTime fromDate, DateTime todate)
        {
            int[] arrayint = new int[CboSelected.Items.Count];
            int cnt = 0;
            foreach (object item in CboSelected.Items)
            {
                DataRowView drw = (DataRowView)item;
                arrayint[cnt++] = Convert.ToInt32(drw[CboSelected.ValueMember].ToString());
            }


            ReportDocument cryRpt = new Report.SOA();

            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            ParameterField paramField2 = new ParameterField();
            //ParameterFields paramFields2 = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();


            ParameterField paramField3 = new ParameterField();
            //ParameterFields paramFields3 = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue3 = new ParameterDiscreteValue();

            ParameterField paramField4 = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue4 = new ParameterDiscreteValue();

            ////Set instances for input parameter 1 -  @vDepartment
            paramField.Name = "@AccountId";

            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue.Value = null; //CboBuyer.SelectedValue;
            paramField.CurrentValues.Add(paramDiscreteValue);
            //paramField.CurrentValues.Add(paramDiscreteValue);
            //Add the paramField to paramFields
            paramFields.Add(paramField);

            //Set instances for input parameter 1 -  @vDepartment
            paramField2.Name = "@fromDate";

            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue2.Value = fromDate;
            paramField2.CurrentValues.Add(paramDiscreteValue2);
            //Add the paramField to paramFields
            paramFields.Add(paramField2);

            //Set instances for input parameter 1 -  @vDepartment
            paramField3.Name = "@toDate";
          
            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue3.Value = todate;
            paramField3.CurrentValues.Add(paramDiscreteValue3);
            //Add the paramField to paramFields
            paramFields.Add(paramField3);

            paramField4.Name = "cName";

            //Below variable can be set to any data present in SalseData table, Department column
            paramDiscreteValue4.Value = Globalclass.CompanyName;
            paramField4.CurrentValues.Add(paramDiscreteValue4);
            //Add the paramField to paramFields
            paramFields.Add(paramField4);


            crystalReportViewer1.ParameterFieldInfo = paramFields;
            cryRpt.SetParameterValue("AccountIds", arrayint);
            cryRpt.DataSourceConnections[0].SetConnection(Globalclass.DsnName, Globalclass.DbName, "atul", "vikas");
            cryRpt.SetDatabaseLogon("atul", "vikas", Globalclass.DsnName, Globalclass.DbName, false);
            cryRpt.Database.Tables[0].Location = Globalclass.DsnName + ".dbo." + cryRpt.Database.Tables[0].Name; ;
            crystalReportViewer1.ReportSource = cryRpt;

        }

        private void frmrptSOA_Load(object sender, EventArgs e)
        {
            Colorprj.Masters.BuyerManager bm = new Colorprj.Masters.BuyerManager();
            CboBuyer.DataSource = bm.GetAllBuyers().Tables[0];
            CboBuyer.DisplayMember = "BuyerName";

            CboBuyer.ValueMember = "BuyerId";
            CboBuyer.SelectedIndex = -1;


        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {

        }

        private void CboBuyer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CboBuyer.SelectedIndex > -1)
            {
                CboSelected.Items.Add(CboBuyer.SelectedItem);
                CboSelected.DisplayMember = "BuyerName";
                CboSelected.ValueMember = "BuyerId";
            }
        }

        private class Item
        {
            public string Name;
            public int Value;
            public Item(string name, int value)
            {
                Name = name; Value = value;
            }
        }

        private void CboBuyer_MouseDoubleClick(object sender, MouseEventArgs e)
        {

        }

        private void CboBuyer_MouseClick(object sender, MouseEventArgs e)
        {

        }

        private void CboBuyer_Click(object sender, EventArgs e)
        {

        }

        private void CboBuyer_Enter(object sender, EventArgs e)
        {

        }

        private void CboSelected_SelectedIndexChanged(object sender, EventArgs e)
        {
            CboSelected.Items.Remove(CboSelected.SelectedItem);
        }

    }
}